<?php if (count($this->courses)): ?>
<table class="table table-bordered" >
    
    <thead>
        <tr>
          <th><?php echo $this->translate('Название курса')?></th>
          <th><?php echo $this->translate('Описание')?></th>
          <th><?php echo $this->translate('Рейтинг')?></th>
          <th><?php echo $this->translate('Действия')?></th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($this->courses as $item):?>
    <tr>
        <td width="20%"><a href="/courses/view/id/<?php echo $item['course_id'] ?>">
            <h4><?php echo $this->escape($item['name']) ?></a></h4></td>
        <td width="65%"><h5 class="nobold"><?php echo $this->escape($item['description']); ?></h5></td>
        <td width="10%"> <h5 class="nobold">
            <center>
                <?php 
                    $_dbTableLec = new Model_DbTable_Lectures();
                    $selectLec = $_dbTableLec->select();
                    $selectLec->where('course_id = ?', $item['course_id']);
                    $_rowLec = $_dbTableLec->fetchAll($selectLec);

                    $sumV = 0;
                    $sumC = 0;

                    foreach ($_rowLec as $itemf){
                        $sumV += $itemf['rank_value'];
                        $sumC += $itemf['rank_count'];
                    }
                    if($sumC) echo round($sumV / $sumC, 1);
                    else echo $this->translate('Оценок нет');
                ?>
            </center></h5>
        </td>        
        <td>
            <a class="btn btn-inverse" 
               style="margin-top: 5px; width: 138px;" 
               href ="
                <?php echo $this->url(array(
                'controller'=>'courses',
                'action'=>'view',
                'id'=>$item['course_id'],
                )); ?>"><?php echo $this->translate('Просмотреть курс')?></a><br>
            <?php if ($this->username != 'гость'): ?>
                <?php 
                    $timeline = new Model_Subscribe();            
                    $this->isVisited = count($timeline->checkSubscribe($item['course_id'],
                            $this->user_id));  
                    if(!$this->isVisited):                        
                 ?>
                 <a class="btn btn-success" style="margin-top: 5px;" 
                   href ="/courses/subscribe/sid/<?php echo $this->sid; ?>/cid/<?php echo $item['course_id'] ?>">
                    <?php echo $this->translate('Подписаться на курс')?> </a>
                 <?php else: ?>
                 <a class="btn btn-danger" style="margin-top: 5px;" 
                   href ="/courses/unsubscribe/sid/<?php echo $this->sid; ?>/cid/<?php echo $item['course_id'] ?>">
                    <?php echo $this->translate('Отписаться от обновлений')?> </a>
                 <?php endif; ?>
            <?php endif; ?>
        </td>
    </tr>
<?php
    endforeach; ?>
    </tbody>
    </table>
<?php else:
?>
    <p><?php echo $this->translate('В этом разделе еще нет курсов.')?>
           </p>
<?php endif ?>
